<?php

declare(strict_types=1);

namespace app\admin\controller;

use app\BaseController;
use app\common\model\User\Record as RecordModel;
use think\facade\Db;

class Record extends BaseController
{
    protected $middleware = [
        \app\admin\middleware\LoginAuth::class
    ];
    // 消费记录列表
    public function index()
    {
        $menu = [
            'name' => '用户管理',
            'title' => '消费记录'
        ];
        $searchfield = $this->request->param('search_field', 'nickname');
        $keyword = $this->request->param('keyword');
        // 接收用户列表带来的userid
        $userid = $this->request->param('userid');
        // halt($param);
        $where = [];
        if ($searchfield && $keyword) {
            $where[] = [$searchfield, 'like', "%$keyword%"];
        }
        if ($userid) {
            $where[] = ['userid', '=', $userid];
        }
        // 每页显示数量
        $num = 10;
        $RecordList = RecordModel::withJoin(['user'])->where('deletetime', 'exp', Db::raw('IS NULL'))->where($where)->order('createtime', 'desc')->paginate(['list_rows' => $num, 'query' => request()->param()]);
        // 当前页
        $page = $RecordList->currentPage();
        return view('', [
            'menu' => $menu,
            'RecordList' => $RecordList,
            'num' => $num,
            'page' => $page,
            'searchfield' => $searchfield,
            'keyword' => $keyword
        ]);
    }
}
